﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace DemoSimple
{

    using OxyPlot;
    using OxyPlot.Axes;
	using OxyPlot.Series;

    public class MainViewModel
    {
        public MainViewModel()
        {

            var myplot = new PlotModel();

            myplot.Title = "График";
			myplot.Axes.Add(new LinearAxis
			{
				Title = "Ось икс",
				Position = AxisPosition.Bottom,
				MinimumPadding = 0.0d,
				MaximumPadding = 0.0d,
				MajorGridlineStyle = LineStyle.Solid,
				MinorGridlineStyle = LineStyle.Dot,
			});

			myplot.Axes.Add(new LinearAxis
			{
				Title = "Ось игрек",
				Position = AxisPosition.Left,
				MinimumPadding = 0.0d,
				MaximumPadding = 0.0d,
				MajorGridlineStyle = LineStyle.Solid,
				MinorGridlineStyle = LineStyle.Dot,
			});

			var mcc = File.ReadAllLines(@"..\results-01.txt").ToArray();
			Int32 nrex = mcc.Length;

			DataPoint[] EnItems = new DataPoint[nrex];
			DataPoint[] ShItems = new DataPoint[nrex];

			Int32 nc = 0;
			foreach( var stt in mcc)
			{
				var xx = stt.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(Convert.ToDouble).ToArray();
				EnItems[nc] = new DataPoint(nc+1, xx[0]);
				ShItems[nc] = new DataPoint(nc+1, xx[1]);
//				ShItems[nc] = new DataPoint(nc + 1, 20 * xx[2]);
				nc = nc + 1;
			}

			var linesers1 = new LineSeries
			{
				StrokeThickness = 1,
				ItemsSource = EnItems
			};

			var linesers2 = new LineSeries
			{
				StrokeThickness = 1,
				ItemsSource = ShItems
			};


			myplot.Series.Add(linesers1);
			myplot.Series.Add(linesers2);

            Model = myplot;
        }

		public PlotModel Model
		{
			get;
			set;
		}
	}
}
